import {
  listColumns,
} from './index.const';
import {
  pageListGroupBY,
  queryOriginalFactoryList,
  deleteBySupplier
} from '@api/system_config_v1.js';
import AddForm from './detail/index.vue'
import ElEditable from '@components/el-editable';

export default {
  components: {
    ElEditable,
    AddForm
  },
  data() {
    return {
      // 多条件查询订单
      tableQuery: {
        supplierCode: ''
      },
      tableLoading: false,
      dialogVisible: false,
      listColumns: listColumns, //表头
      //列表数据
      payload: {},
      loading: false,
      editOrderTypeId: '',
      //销售对象下拉
      originalFactoryList: [],
      //经销商下拉
      // 主列表分页
      currentPage: 1,
      pageSize: 20
    };
  },
  created() {
    this.getList();
  },
  mounted() {

  },
  methods: {
    // 重置
    queryFormReset() {
      this.tableQuery = {
        supplierCode: ''
      }
      this.currentPage = 1;
      this.getList();
    },
    closeDialog () {
      console.log('close')
      this.editOrderTypeId = ''
      this.$refs.addFormRef.clearForm()
      this.dialogVisible = false
    },
    onSubmit () {
      this.$refs.addFormRef.onSubmit()
    },
    onSaveSuccess () {
      this.closeDialog()
      this.getList()
    },
    // 查询
    queryFormQuery() {
      this.currentPage = 1;
      this.getList();
    },
    // 原厂下拉
    queryOriginalFactoryList (val) {
      if (val !== '') {
        this.loading = true;
        let query = {
          originalFactoryName: val,
        };
        this.$axios.$post(queryOriginalFactoryList, query).then(res => {
          this.originalFactoryList = res.payload;
          this.loading = false;
        });
      }
    },
    // 主列表数据
    getList() {
      this.tableLoading = true;
      const query = {
        ...this.tableQuery,
        page: this.currentPage,
        pageSize: this.pageSize
      };
      this.$axios.$post(pageListGroupBY, query).then(res => {
        if (res.code === '0') {
          res.payload.content = res.payload.content || []
          this.payload = res.payload;
        }
        this.tableLoading = false;
      });
    },
    // 主列表分页器
    reloadProductData(val) {
      this.currentPage = val.number
      this.pageSize = val.size
      this.getList();

    },
    onAdd () {
      this.dialogVisible = true
      // this.$router.push({
      //   path: '/system-config/order-type-configuration/detail'
      // })
    },
    onEdit (item) {
      // this.$router.push({
      //   path: '/system-config/order-type-configuration/detail',
      //   query: {
      //     supplierCode: item.supplierCode
      //   }
      // })
      this.editOrderTypeId = item.supplierCode
      this.dialogVisible = true
      this.$nextTick(() => {
        this.$refs.addFormRef.getInfo()
      })
    },
    onDelete (item) {
      this.$confirm('确定要删除该数据吗?', '删除', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        const url = deleteBySupplier + '?supplierCode=' + item.supplierCode
        this.$axios.$get(url).then(res => {
          this.getList()
          this.$message.success('删除成功')
        })
      }).catch(() => {
        this.$message.info('已取消删除')
      })
    }
  }
};
